﻿/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef DEF_KARAZHAN_H
#define DEF_KARAZHAN_H

#define DataHeader "KZ"

uint32 const EncounterCount = 12;

enum KZDataTypes
{
    DATA_ATTUMEN = 0,
    DATA_MOROES = 1,
    DATA_MAIDEN = 2,
    DATA_OPTIONAL_BOSS = 3,
    DATA_OPERA_PERFORMANCE = 4,
    DATA_CURATOR = 5,
    DATA_ARAN = 6,
    DATA_TERESTIAN = 7,
    DATA_NETHERSPITE = 8,
    DATA_CHESS = 9,
    DATA_MALCHEZZAR = 10,
    DATA_NIGHTBANE = 11,
    DATA_SERVANT_QUARTERS = 12,
    DATA_SELECTED_RARE = 13,

    DATA_OPERA_OZ_DEATHCOUNT = 14,

    DATA_KILREK = 15,
    MAX_ENCOUNTERS = 16,
    DATA_GO_CURTAINS = 18,
    DATA_GO_STAGEDOORLEFT = 19,
    DATA_GO_STAGEDOORRIGHT = 20,
    DATA_GO_LIBRARY_DOOR = 21,
    DATA_GO_MASSIVE_DOOR = 22,
    DATA_GO_NETHER_DOOR = 23,
    DATA_GO_GAME_DOOR = 24,
    DATA_GO_GAME_EXIT_DOOR = 25,

    DATA_IMAGE_OF_MEDIVH = 26,
    DATA_MASTERS_TERRACE_DOOR_1 = 27,
    DATA_MASTERS_TERRACE_DOOR_2 = 28,
    DATA_GO_SIDE_ENTRANCE_DOOR = 29,
    DATA_PRINCE = 30,

    DATA_TEAM_IN_INSTANCE,
    DATA_CHESS_DAMAGE

};

enum KZOperaEvents
{
    EVENT_OZ = 1,
    EVENT_HOOD = 2,
    EVENT_RAJ = 3
};

enum KZMiscCreatures
{
    NPC_HYAKISS_THE_LURKER = 16179,
    NPC_ROKAD_THE_RAVAGER = 16181,
    NPC_SHADIKITH_THE_GLIDER = 16180,
    NPC_TERESTIAN_ILLHOOF = 15688,
    NPC_MOROES = 15687,
    NPC_ATTUMEN_THE_HUNTSMAN = 15550,
    NPC_ATTUMEN_THE_HUNTSMAN_MOUNTED = 16152,
    NPC_NIGHTBANE = 17225,

    // Trash
    NPC_COLDMIST_WIDOW = 16171,
    NPC_COLDMIST_STALKER = 16170,
    NPC_SHADOWBAT = 16173,
    NPC_VAMPIRIC_SHADOWBAT = 16175,
    NPC_GREATER_SHADOWBAT = 16174,
    NPC_PHASE_HOUND = 16178,
    NPC_DREADBEAST = 16177,
    NPC_SHADOWBEAST = 16176,
    NPC_KILREK = 17229,
    NPC_RELAY = 17645,

    NPC_NIGHTBANE_HELPER = 17260,
    NPC_NETHERSPITE = 15689,
    NPC_ECHO_MEDIVH = 16816,
    NPC_INVISIBLE_STALKER = 22519,                    // placeholder for dead chess npcs
    NPC_CHESS_STATUS_BAR = 22520,                    // npc that controlls the transformation of dead pieces
    NPC_CHESS_VICTORY_CONTROLLER = 22524,

    // Chess event
    NPC_ORC_GRUNT = 17469,                    // pawn
    NPC_ORC_WOLF = 21748,                    // knight
    NPC_ORC_WARLOCK = 21750,                    // queen
    NPC_ORC_NECROLYTE = 21747,                    // bishop
    NPC_SUMMONED_DAEMON = 21726,                    // rook
    NPC_WARCHIEF_BLACKHAND = 21752,                    // king
    NPC_HUMAN_FOOTMAN = 17211,                    // pawn
    NPC_HUMAN_CHARGER = 21664,                    // knight
    NPC_HUMAN_CONJURER = 21683,                    // queen
    NPC_HUMAN_CLERIC = 21682,                    // bishop
    NPC_CONJURED_WATER_ELEMENTAL = 21160,                    // rook
    NPC_KING_LLANE = 21684,                    // king
    NPC_SQUARE_WHITE = 17208,                    // chess white square
    NPC_SQUARE_BLACK = 17305,                    // chess black square


};

enum KZGameObjectIds
{
    GO_STAGE_CURTAIN = 183932,
    GO_STAGE_DOOR_LEFT = 184278,
    GO_STAGE_DOOR_RIGHT = 184279,
    GO_PRIVATE_LIBRARY_DOOR = 184517,
    GO_MASSIVE_DOOR = 185521,
    GO_GAMESMAN_HALL_DOOR = 184276,
    GO_GAMESMAN_HALL_EXIT_DOOR = 184277,
    GO_NETHERSPACE_DOOR = 185134,
    GO_MASTERS_TERRACE_DOOR = 184274,
    GO_MASTERS_TERRACE_DOOR2 = 184280,
    GO_SIDE_ENTRANCE_DOOR = 184275,
    GO_DUST_COVERED_CHEST = 185119,

};

enum KZMisc
{
    OPTIONAL_BOSS_REQUIRED_DEATH_COUNT = 50
};

enum KarazhanSpells
{
    SPELL_RATTLED = 32437,
    SPELL_OVERLOAD = 29766,
    SPELL_BLINK = 29884
};

enum Miscs
{
    FACTION_ID_CHESS_HORDE = 1689,
    FACTION_ID_CHESS_ALLIANCE = 1690
};

enum Actions
{
    AI_EVENT_CUSTOM_A = 1,
    AI_EVENT_CUSTOM_B = 2,
};


class instance_karazhan : public InstanceMapScript
{
public:
    instance_karazhan() : InstanceMapScript("instance_karazhan", 532) { }

    InstanceScript* GetInstanceScript(InstanceMap* map) const override
    {
        return new instance_karazhan_InstanceMapScript(map);
    };

    struct instance_karazhan_InstanceMapScript : public InstanceScript
    {
        instance_karazhan_InstanceMapScript(Map* map) : InstanceScript(map) { }

        void OnCreatureCreate(Creature* creature);
        void Initialize();
        void OnUnitDeath(Unit* unit);
        void SetData(uint32 type, uint32 data);
        bool SetBossState(uint32 type, EncounterState state);
        void SetData64(uint32 type, uint64 data);
        void OnGameObjectCreate(GameObject* go);
        uint32 GetData(uint32 type) const;
        uint64 GetData64(uint32 data) const;

        void OnPlayerEnter(Player* player);
        bool IsFriendlyGameReady();
        void GetChessPiecesByFaction(std::list<uint64 >& lList, uint32 uiFaction) { lList = uiFaction == FACTION_ID_CHESS_ALLIANCE ? m_lChessPiecesAlliance : m_lChessPiecesHorde; }
        bool IsCaseOccupied(Creature* creature);
        void DoMoveChessPieceToSides(uint32 uiSpellId, uint32 uiFaction, bool bGameEnd = false);

        void DoPrepareChessEvent();
        void Update(uint32 uiDiff);
        std::string GetSaveData();
        void Load(char const* chrIn);

    private:
        uint32 OperaEvent;
        uint32 OzDeathCount;
        uint32 OptionalBossCount;
        uint64 m_uiCurtainGUID;
        uint64 m_uiStageDoorLeftGUID;
        uint64 m_uiStageDoorRightGUID;
        uint64 m_uiKilrekGUID;
        uint64 m_uiTerestianGUID;
        uint64 m_uiMoroesGUID;
        uint64 m_uiNightBaneGUID;
        //uint64 EchoOfMedivhGUID;
        uint64 m_uiLibraryDoor;                                     // Door at Shade of Aran
        uint64 m_uiMassiveDoor;                                     // Door at Netherspite
        uint64 m_uiSideEntranceDoor;                                // Side Entrance
        uint64 m_uiGamesmansDoor;                                   // Door before Chess
        uint64 m_uiGamesmansExitDoor;                               // Door after Chess
        uint64 m_uiNetherspaceDoor;                                // Door at Malchezaar
        //uint64 m_uiServantsAccessDoor;                              // Door to Brocken Stair
        uint64 MastersTerraceDoor[2];
        uint64 ImageGUID;
        uint64 DustCoveredChest;
        uint64 m_uiRelayGUID;

        uint32 m_uiTeam;
        uint32 m_uiChessResetTimer;
        uint32 m_uiAllianceStalkerCount;
        uint32 m_uiHordeStalkerCount;
        bool m_bFriendlyGame;
        uint64 m_HordeStatusGuid;
        uint64 m_AllianceStatusGuid;

        std::string strSaveData;

        std::list<uint64 > m_lNightbaneGroundTriggers;
        std::list<uint64 > m_lNightbaneAirTriggers;

        std::list<uint64 > m_lChessHordeStalkerList;
        std::list<uint64 > m_lChessAllianceStalkerList;
        std::list<uint64 > m_lChessPiecesAlliance;
        std::list<uint64 > m_lChessPiecesHorde;
        std::vector<uint64 > m_vHordeStalkers;
        std::vector<uint64 > m_vAllianceStalkers;

        uint32 m_ChessState;
        uint64 m_uiMedivhGUID;
        uint64 m_uiChessVicConGUID;

        uint32 m_uiChessDamages;
    };
};

#endif
